package com.duk.service.impl;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import javax.annotation.Resource;

import org.springframework.stereotype.Service;

import com.duk.dao.DeptMapper;
import com.duk.model.Dept;
import com.duk.service.DeptService;
import com.duk.util.PageBean;

/** 
* @author  by: kasher
* @date 创建时间：2017年1月7日 下午9:47:57 
* @version 1.0 * @parameter  
* @since  
* @return  
*/
/**
 *
 * DeptService by:kasher 2017年1月7日 下午9:47:57 我乃压身第一人
 * 
 * @version 1.0.0
 *
 */
@Service
public class DeptServiceImpl implements DeptService
{

	@Resource
	private DeptMapper deptMapper;

	/*
	 * (non-Javadoc)
	 * 
	 * @see com.duk.service.DeptService#list()
	 */
	@Override
	public List<Dept> list()
	{
		// TODO Auto-generated method stub
		return deptMapper.list();
	}

	/*
	 * (non-Javadoc)
	 * 
	 * @see com.duk.service.DeptService#add(com.duk.model.Dept)
	 */
	@Override
	public void add(Dept dept)
	{
		deptMapper.add(dept);

	}

	@Override
	public PageBean getPageByCondition(int pageIndex, int pageSize, String deptName)
	{
		Map<String, Object> map = new HashMap<String, Object>();
		map.put("start", pageIndex * pageSize);
		map.put("limit", pageSize);
		map.put("orderByClause", "deptID desc");
		map.put("deptName", deptName);
		// deptID,deptName,digest
		int total = deptMapper.countByCondition(map);

		PageBean pb = new PageBean(total, pageIndex, pageSize);

		pageIndex = pb.getPageIndex();

		List<Dept> data = deptMapper.selectPageByCondition(map);

		pb.setData(data);

		return pb;
	}

	@Override
	public Dept getById(Integer deptID)
	{
		return deptMapper.getById(deptID);
	}

	public void update(Dept dept)
	{
		deptMapper.update(dept);

	}

	/*
	 * (non-Javadoc)
	 * 
	 * @see com.duk.service.DeptService#deleteByPKs(java.lang.Integer[])
	 */
	@Override
	public void deleteByPKs(Integer[] deptID)
	{
		for (int i = 0; i < deptID.length; i++)
		{
			deptMapper.deleteByPrimaryKey(deptID[i]);
		}

	}

}